using System;
using System.Threading.Tasks;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Solution.Application.Extensions;
using Solution.Application.Injection;
using Solution.Core.Dependency;

namespace Solution.WebHost
{
    public class Program
    {
        public static async Task Main(string[] args)
        {
            await CreateHostBuilder(args).Build().RunAsync();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .ConfigureAppConfiguration((app, config) =>
            {
                config.AddJsonFile("Configs/jwt.json", true, true);
                config.AddJsonFile("Configs/rabbit.json", true, true);
                config.AddJsonFile("Configs/jaeger.json", true, true);
            })
            .ConfigureLogging(configureLogging =>
            {
                configureLogging.ClearProviders();
                configureLogging.AddConsole();
                configureLogging.SetMinimumLevel(LogLevel.Information);
                configureLogging.AddNLog("Configs/nlog.config");
            })
            .UseServiceProviderFactory(new AutofacServiceProviderFactory(container =>
            {
                container.AddPipelineBehaviors();
                container.AddAssembly(typeof(ITransientDependency), "Solution.Application");
            }));
    }
}